package com.mansoor.app.islamicnames.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import com.mansoor.app.islamicnames.beans.State;
import static com.mansoor.app.islamicnames.beans.State.put;
import static com.mansoor.app.islamicnames.util.AppConstant.*;

/**
 * Created by IntelliJ IDEA.
 * User: Mansoor
 * Date: Oct 13, 2009
 * Time: 10:21:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main extends Activity
{
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        final Spinner alphaMenu = (Spinner) findViewById(R.id.alphabet);
        ArrayAdapter alphabetsAdapter = ArrayAdapter.createFromResource(this, R.array.alphabets, android.R.layout.simple_spinner_item);
        alphabetsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        alphaMenu.setAdapter(alphabetsAdapter);

        final Spinner genderMenu = (Spinner) findViewById(R.id.gender);
        ArrayAdapter genderAdapter = ArrayAdapter.createFromResource(this, R.array.gender, android.R.layout.simple_spinner_item);
        genderAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        genderMenu.setAdapter(genderAdapter);

        Button submitButton = (Button) findViewById(R.id.submit);

        submitButton.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                initState();
                final String alphabet = alphaMenu.getSelectedItem().toString();
                final String gender = genderMenu.getSelectedItem().toString();
                Log.i("alphabet", alphabet);
                Log.i("gender", gender);

                State.put(GENDER, gender);
                State.put(ALPHABET, alphabet);

                Intent intent = new Intent(view.getContext(), NameList.class);

                startActivity(intent);
            }
        });


    }

    private void initState()
    {
        put(PAGE_COUNT, 0);
        put(GENDER, null);
        put(ALPHABET, null);
        put(CURRENT_PAGE, 0);
        put(FIRSTRUN, true);
        put(SELECTED_NAME, null);
    }


}
